package com.rong.tools.controller;

import com.rong.tools.entity.pojo.Category;
import com.rong.tools.service.CategoryService;
import com.rong.tools.entity.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 周厚荣
 * @date 2025/4/20 23:21
 */
@RestController
@RequestMapping("/category")
public class CategoryController extends ABaseController{
    @Autowired
    private CategoryService categoryService;
    @GetMapping
    public ResponseVO getAllCategories() {
        List<Category> allCategories = categoryService.getAllCategories();
        return getSuccessResponseVO(allCategories);
    }

    @GetMapping("/{id}")
    public ResponseVO getCategoryById(@PathVariable Integer id) {
        Category categoryById = categoryService.getCategoryById(id);
        return getSuccessResponseVO(categoryById);
    }

    @PostMapping
    public ResponseVO addCategory(@RequestBody Category category) {
        categoryService.addCategory(category);
        return getSuccessResponseVO(null);
    }

    @PutMapping
    public ResponseVO updateCategory(@RequestBody Category category) {
        categoryService.updateCategory(category);
        return getSuccessResponseVO(null);
    }

    @DeleteMapping("/{id}")
    public ResponseVO deleteCategory(@PathVariable Integer id) {
        System.out.println("hello"+id);
        categoryService.deleteCategory(id);
        return getSuccessResponseVO(null);
    }
}
